package cn.momo.mobile.nearby.adapter;

import java.util.ArrayList;
import java.util.List;

import cn.momo.mobile.R;
import cn.momo.mobile.view.RemoteImageView;

import android.app.Activity;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView.ScaleType;

/**
 *
 *
 */
public class NearInfoAdapter extends BaseAdapter{
	private Context mContext;
	private List<String> mData;
	boolean isadd = false;
	
	public NearInfoAdapter(Context context,List<String> list){
		mContext = context;
		
		if(list != null){
			mData = list;
		}else {
			mData = new ArrayList<String>();
		}
	}
	
	public NearInfoAdapter(Context context,List<String> list, boolean flag){
		mContext = context;
		
		if(list != null){
			mData = list;
			if(flag && list.size() < 8){
				mData.add("");
				isadd = true;
			}
		}else {
			mData = new ArrayList<String>();
			mData.add("");
			isadd = true;
		}

	}
	
	@Override
	public int getCount() {
		return mData.size();
	}

	@Override
	public Object getItem(int position) {
		return mData.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if(isadd && position == mData.size()-1){
			System.out.println("this is the end added one");
		}
		RemoteImageView imageView = new RemoteImageView(mContext);
		imageView.setMinimumWidth(100);
		imageView.setMinimumHeight(100);
		imageView.setScaleType(ScaleType.FIT_XY);
		imageView.setImageResource(R.drawable.sina_photo);
		imageView.setImageUrl(mData.get(position), (Activity) mContext, 100, 100);
		return imageView;
	}

}
